package com.lc.afbx.adapters;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.conn.GetApiShangJiaRuZhu;
import com.zcx.helper.util.UtilLog;

import java.util.List;

/**
 * Created by Administrator on 2016/6/3.
 */
public class RuZhuAdapter extends BaseAdapter {
    private List<GetApiShangJiaRuZhu.Data> dataList;
    private LayoutInflater inflater;

    public RuZhuAdapter(Context context, List<GetApiShangJiaRuZhu.Data> dataList) {
        inflater = LayoutInflater.from(context);
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {

            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_shangjia_ruzhu, null);
            BaseApplication.ScaleScreenHelper.loadView((ViewGroup) convertView);

            holder.txt = (TextView) convertView.findViewById(R.id.txt);
            holder.img = (SimpleDraweeView) convertView.findViewById(R.id.img);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

//        UtilLog.e("这是ruzhuadapter里", dataList.get(position).picurl + " " + dataList.size());
        holder.txt.setText(dataList.get(position).title);

        holder.img.setImageURI(Uri.parse(dataList.get(position).picurl));

        return convertView;
    }

    class ViewHolder {
        TextView txt;
        SimpleDraweeView img;
    }
}
